package cn.medemede.dao;

import cn.medemede.dbc.DatabaseConnection;
import cn.medemede.model.Pattern;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class PatternDao {
    public static Pattern getPattern(int pid) throws SQLException {
        Connection connection= DatabaseConnection.getConnection();
        String FindSQL = "select * from patterns2 where pid=?";
        PreparedStatement preparedStatement=connection.prepareStatement(FindSQL);
        preparedStatement.setInt(1,pid);
        ResultSet rs=preparedStatement.executeQuery();

        Pattern pattern=new Pattern();
        pattern.setPid(pid);
        while (rs.next()){
            pattern.setPname(rs.getString("pname"));
            pattern.setPinfo(rs.getString("pinfo"));
            pattern.setPusedimg(rs.getString("pusedimg"));
            pattern.setPused(rs.getString("pused"));
            pattern.setPmain(rs.getString("pmain"));
            pattern.setPuml(rs.getString("puml"));
            pattern.setPcodeinfo(rs.getString("pcodeinfo"));
            pattern.setPcode(rs.getString("pcode"));
            pattern.setPcodepr(rs.getString("pcodepr"));
            pattern.setOther(rs.getString("other"));
            pattern.setPcodeuml(rs.getString("pcodeuml"));
            pattern.setPnameEn(rs.getString("pnameen"));
        }
        return pattern;
    }
}
